using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Assets.Scripts.GDK
{
	public class gdk_module_manger
	{
		public static gdk_module_manger _instance;

		private List<gdk_Imodule> _moduleList = new List<gdk_Imodule>();

		public static gdk_module_manger Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new gdk_module_manger();
				}
				return _instance;
			}
			set
			{
				_instance = value;
			}
		}

		public gdk_module_manger()
		{
			IEnumerable<Type> enumerable = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => from t in a.GetTypes()
				where Enumerable.Contains(t.GetInterfaces(), typeof(gdk_Imodule))
				select t);
			foreach (Type item2 in enumerable)
			{
				if (item2.IsClass)
				{
					gdk_Imodule item = Activator.CreateInstance(item2) as gdk_Imodule;
					_moduleList.Add(item);
				}
			}
		}

		public T Module<T>()
		{
			foreach (gdk_Imodule module in _moduleList)
			{
				if (typeof(T) == module.GetType())
				{
					return (T)module;
				}
			}
			return default(T);
		}
	}
}
